package com.pine.sunshineelder.common;

import java.util.UUID;

public interface StringHelper {
	
		/**
		 * 自动生成id
		 * @return
		 */
	 default String uuid() {
		String uuid = UUID.randomUUID().toString();
		char[] cs = new char[32];
		for (int i = uuid.length(), j = 0; i-- > 0;) {
			if (uuid.charAt(i) != '-') {
				cs[j++] = uuid.charAt(i);
			}
		}
		return new String(cs);
	}
	 /**
	  * 判断输入是否为空字符串,把空字符串转换为空
	  * @param target
	  * @return
	  */
	default String trimAsNull(String target) {

		if (target == null || (target = target.trim()).length() == 0) {
			return null;
		}
		return target;
	}
	/**
	 * 把字符串转换为int类型
	 * @param s
	 * @param defaultValue
	 * @return
	 */
	default Integer parseInt(String s, Integer defaultValue) {
		s=trimAsNull(s);
		if (s== null)
			return defaultValue;
		try {
			return Integer.parseInt(s);
		} catch (NumberFormatException e) {
			return defaultValue;
		}
	}

}
